package com.laolei.core.rest.http;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.AsyncClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

	@Bean
	@ConditionalOnBean(AsyncClientHttpRequestFactory.class)
	AsyncRestTemplate asyncRestTemplate(AsyncClientHttpRequestFactory clientHttpRequestFactory) {
		return new AsyncRestTemplate(clientHttpRequestFactory);
	}

	@Bean
	@ConditionalOnBean(ClientHttpRequestFactory.class)
	RestTemplate restTemplate(ClientHttpRequestFactory clientHttpRequestFactory) {
		return new RestTemplate(clientHttpRequestFactory);
	}
}
